function [ha] = an_hist()
%
% call the ASM model (MatlabDemo) and make a psth
%
freq = 8000.0; % khz
inten = 30.0; % db SPL
stimdur = 0.1; % seconds
delay_totone = 2.0; % delay to stimulus, seconds
end_silence = 0.05; % silence after stimulus, seconds
spont = 'high';
nrep = 50;

stimstart = delay_totone*1000;
bw = 2;
maxpsth = 1000*(delay_totone+stimdur+end_silence);
x=(0:bw:maxpsth);
isibw = 0.5;

maxisi = stimdur*1000;
xi = (0:isibw:maxisi);
h=zeros(length(x),1);
hi = zeros(length(xi), 1);
t={};
% to make an array for the stimulus, we generate an histogram with the 
% requisite bin width
hbw = 0.1;
ha = zeros(nrep, floor(maxpsth/hbw)); % it can be a big array histogram 
for i = 1:nrep
  fprintf(1, 'rep: %d\r', i);
   r = an_generate2(spont, freq, inten, delay_totone, stimdur, end_silence, seed1, seed2);
   %t=r(:,1);
   th = floor(r(:,1)*1000/bw)+1;
   iok = find(th <= length(x));
   h(th(iok)) = h(th(iok)) + 1;
   % compute fine histo for stimulation
   th = floor(r(:,1)*1000/hbw)+1;
   iok = find(th <= size(ha, 2));
   ha(i, th(iok)) = ha(i, th(iok))+1;
   % compute isi 
   tisi = find(r(:,1) < stimstart/1000); % spont window
   ti = floor(diff(r(tisi,1)*1000/isibw))+1;
   iok = find(ti <= length(xi));
   hi(ti(iok)) = hi(ti(iok)) + 1;
end;
plot(x,h);
figure;
plot(xi, hi);
